
/*
    Copyright 2011,2012 Calum Stuart Cookson.

    This file is part of Bio Mongoose.

    Bio Mongoose is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bio Mongoose is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bio Mongoose.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>

#include "creational.hpp"
#include "analysis.h"
#include "utility.h"
#include "program_args.h"
#include "distinct_excluded_blocks.h"

using namespace std;

void output_initial_message(ostream &out);
void output_full_help(ostream &out);

int main(int argc, char *argv[])
{
    output_initial_message(cerr);
    program_args args;
    args.parse(argc, argv);

    if(args.has_switch("--help"))
    {
        output_full_help(cerr);
    }

    string sequence_to_analyse = utility::get_file(args.get_argument(1));

    cerr << "Max DEB length " << log(sequence_to_analyse.length()) << endl;
    int upper_bound = log(sequence_to_analyse.length());

    time_t start = clock();
    analysis a;

       a.analyse(sequence_to_analyse, upper_bound);



    time_t end = clock();
    cout << "Sequence[" << args.get_argument(1) << "]" << endl;
    cout << "Length[" << sequence_to_analyse.length() << "]" << endl;
    a.report(cout);
    cout << "#Computation took " << (double)(end-start)/(CLOCKS_PER_SEC) << " seconds." << endl;
    return 0;
}


void output_initial_message(ostream &out)
{
    out << endl;
    out << utility::generate_copyright_notice("Bio Mongoose", "Distinct Excluded Blocks discovery engine", "Copyright (c) 2011,2012 Calum Cookson") << endl;
    out << utility::get_disclaimer_text() << endl;
    out << "Have a nice day." << endl;
    out << "Type: --help for full program arguments" << endl;
    out << endl;
}

void output_full_help(ostream &out)
{
    out << "Usage: bio_mongoose [switches] <sequence> [min_deb_length_to_report = 1 [max_deb_length_to_report = auto]]" << endl << endl;
    out << "Command Switches:" << endl;
    out << "--auto" << endl;
    out << "Auto detect the turning point of the deb length graph and output 1 beyond it." << endl;
    out << "When used in conjunction with max_deb_length_to_report bio_mongoose reports the least of max_deb_length_to_report and the auto detected turning point + 1" << endl;
    out << endl;
    out << "--search_algorithm:{default, brute_force, boyer_moore}" << endl;
    out << "Specify the string search algorithm to use." << endl;
    out << "default is to use std::string::find corresponding to the STL implementation used to compile bio_mongoose" << endl;
    out << endl;
    out << "--hw_accelerated:{true,false}" << endl;
    out << "State explicitly whether hardware acceleration should be used." << endl;
    out << "Default is to use hardware acceleration if present." << endl;
    out << endl;
    out << "--threads:{max_threads}" << endl;
    out << "Maximum number of threads to use for multi threaded operations." << endl;
    out << "Set to 1 to disable multi threading." << endl;
    out << "Default is to disable multi threading." << endl;
    out << endl;
    out << "--report_debs" << endl;
    out << "Can be used to report the actual DEBS of each length." << endl;
    out << "Default is to report only the count." << endl;
    out << endl;
}
